package util.util;


import exception.IocRuntimeException;

/**
 * @author Max
 * <br>
 * date 2019/12/19 10:47
 * @version 0.1
 */

public class ClassUtil {

    /**
     * 获取当前的classloader
     * @return ClassLoader
     * @since 0.1
     */
    public static ClassLoader currentClassLoader() {
        return Thread.currentThread().getContextClassLoader();
    }

    /**
     * 获取类信息
     * @param className string
     * @return class
     * @since 0.1
     */
    public static Class getClass(String className) {
        ArgUtil.notEmpty(className);
        try {
            return currentClassLoader().loadClass(className);
        } catch (ClassNotFoundException e) {
            throw new IocRuntimeException(e);
        }
    }

    /**
     * 直接根据class无参构造 实例
     * @param clazz class
     * @return 实例对象
     * @since 0.1
     */
    public static Object newInstance(Class clazz){
        try {
            return clazz.newInstance();
        } catch (InstantiationException | IllegalAccessException e) {
            throw new IocRuntimeException(e);
        }
    }

}